<?php
/**
编辑文章页面
 */
//编辑需关联数据库,需先获取article_id
$articleId = $_GET['article_id'];

//检测文章Id
if (empty($articleId)){
    echo "文章id错误";
    exit();
}

//连接到数据库
$dsn = "mysql:host=127.0.0.1;dbname=blog";
$db = new PDO($dsn, "root", "123456");

//更改默认的utf8为utf8mb4以防中文乱码
$db->exec("set names utf8mb4");

//php语句mysql查询相关数据
$sql = "select * from article where article_id = '$articleId'";
$result = $db->query($sql);
$articleEdit = $result->fetch(PDO::FETCH_ASSOC);

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/base.css" />
    <link rel="stylesheet" type="text/css" href="css/top.css" />
    <link rel="stylesheet" type="text/css" href="css/right.css" />
    <link rel="stylesheet" type="text/css" href="css/left.css" />
</head>
<body>
<div id="container">
    <div id="top">
        <div id="top_left">
            <span>博客管理系统</span>
        </div>
        <div id="top_right">
            欢迎你：admin <a href="#">退出登录</a>
        </div>
    </div>
    <div id="left">
        <ul>
            <li><a href="#">分类管理</a></li>
            <li><a href="#" id="left_two">文章管理</a></li>
            <li><a href="#">管理员</a></li>
        </ul>
    </div>
    <div id="right">
        <ul>
            <li>
                <a href="#">首页</a>&nbsp;>
                <a href="#">文章管理</a>&nbsp;>
                <a href="#">编辑文章</a>
            </li>
            <li>
                <form id="article_edit_form" action="article_edit_save.php" method="post">
                    <table class="add">
                        <tbody>
                        <tr>
                            <td width="190">文章id:&nbsp;</td>
                            <td><input type="text" value="<?php echo $articleEdit['article_id']; ?>" readonly="readonly" name="article_id"/></td>
                        </tr>
                        <tr>
                            <td width="190">分类id:&nbsp;</td>
                            <td><input type="text" value="<?php echo $articleEdit['category_id']; ?>" readonly="readonly" name="category_id"/></td>
                        </tr>
                        <tr>
                            <td>文章标题:&nbsp;</td>
                            <td>
                                <input type="text" name="article_title" value="<?php echo $articleEdit['article_title']; ?>"/>
                            </td>
                        </tr>
                        <tr>
                            <td>文章简介:&nbsp;</td>
                            <td>
                                <textarea rows="10" cols="30" name="article_intro" ><?php echo $articleEdit['article_intro']; ?></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td>文章内容:&nbsp;</td>
                            <td>
                                <textarea rows="10" cols="30" name="content" ><?php echo $articleEdit['content']; ?></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <input type="submit" class="button" />
                                <input type="reset" class="button" />
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </form>
            </li>
        </ul>
    </div>
</div>
</body>
</html>
